package com.qf.business.user.listener;

import com.qf.business.user.service.RedEnvelopesService;
import com.qf.commons.event.apply.consumer.EventHandler;
import com.qf.commons.event.apply.consumer.IEventHandler;
import com.qf.commons.event.entity.QphoneMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@EventHandler(value = "rob_red_event", isAsync = true)
@Slf4j
@Component
public class RobRedEventListener implements IEventHandler<Map> {

    @Autowired
    private RedEnvelopesService redEnvelopesService;

    @Override
    public void handler(Map eventContent, QphoneMessage qphoneMessage) {
        log.info("[rob red] - 事件总线接收到抢红包的请求 - {}", eventContent);
        long redid = Long.valueOf(eventContent.get("redid") + "");
        long uid = Long.valueOf(eventContent.get("uid") + "");
        long score = Long.valueOf(eventContent.get("score") + "");

        redEnvelopesService.robRedEnvelopoesPlainB(redid, uid, score);
    }
}
